package com.lecture.java8.excel.dyr;

import com.alibaba.excel.EasyExcel;
import com.lecture.java8.excel.DemoDataListener;
import com.lecture.java8.excel.dyr.model.Result0321;
import com.lecture.java8.excel.dyr.model.Result0321_1;
import com.lecture.java8.excel.dyr.model.Result0321_2;
import com.lecture.java8.excel.dyr.model.Result0321_3;
import com.lecture.java8.excel.model.FinanceResult0320;
import com.lecture.java8.excel.model.Result0320;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test0321_2 {
    public static void main(String[] args) {
        String dataResultFileName = "D:\\study\\tmp\\0321\\1\\tWW.xlsx";
        DemoDataListener<Result0320> dataResultListener = new DemoDataListener<>();
        EasyExcel.read(dataResultFileName, Result0320.class,dataResultListener).sheet().doRead();
        List<Result0320> resultList = dataResultListener.getDataList();

        Map<String,String> resultMap = new HashMap<>();
        for (Result0320 result : resultList) {
            String year = result.getC().substring(0,4);
            resultMap.put(result.getA() + "-" + year,result.getD());
        }
        //Map<String, String> resultMap = resultList.stream().collect(Collectors.toMap(r -> r.getId() + "-" + r.getYear(), Result0320::getEast));

        //杭州
        String hzResultFileName = "D:\\study\\tmp\\0321\\1\\杭州-球面距离.xls";
        DemoDataListener<Result0321> hzResultListener = new DemoDataListener<>();
        EasyExcel.read(hzResultFileName, Result0321.class,hzResultListener).sheet().doRead();
        List<Result0321> hzResultList = hzResultListener.getDataList();

        Map<String,String> hzResultMap = new HashMap<>();
        for (Result0321 result : hzResultList) {
            hzResultMap.put(result.getA(),result.getB());
        }
        //杭州

        //研发投入密度
        String yfResultFileName = "D:\\study\\tmp\\0321\\1\\研发投入密度.xlsx";
        DemoDataListener<Result0321_1> yfResultListener = new DemoDataListener<>();
        EasyExcel.read(yfResultFileName, Result0321_1.class,yfResultListener).sheet().doRead();
        List<Result0321_1> yfResultList = yfResultListener.getDataList();

        Map<String,String> yfResultMap = new HashMap<>();
        for (Result0321_1 result : yfResultList) {
            String year = result.getB().substring(0,4);
            yfResultMap.put(result.getA() + "-" + year,result.getC());
        }
        //研发投入密度


        //内部控制指数及评级（2000-2022）
        String nbResultFileName = "D:\\study\\tmp\\0321\\1\\内部控制指数及评级（2000-2022）.xlsx";
        DemoDataListener<Result0321_2> nbResultListener = new DemoDataListener<>();
        EasyExcel.read(nbResultFileName, Result0321_2.class,nbResultListener).sheet().doRead();
        List<Result0321_2> nbResultList = nbResultListener.getDataList();

        Map<String,String> nbResultMap = new HashMap<>();
        for (Result0321_2 result : nbResultList) {
            String code = result.getA().substring(0, result.getA().indexOf('.'));
            long a = Long.parseLong(code);
            String year = result.getC().substring(0,4);
            nbResultMap.put(a + "-" + year,result.getB());
        }
        //内部控制指数及评级（2000-2022）结束

        //研发人员 开始
        String yfryResultFileName = "D:\\study\\tmp\\0321\\1\\研发人员.xlsx";
        DemoDataListener<Result0321_3> yfryResultListener = new DemoDataListener<>();
        EasyExcel.read(yfryResultFileName, Result0321_3.class,yfryResultListener).sheet().doRead();
        List<Result0321_3> yfryResultList = yfryResultListener.getDataList();

        Map<String,Result0321_3> yfryResultMap = new HashMap<>();
        for (Result0321_3 result : yfryResultList) {
            String year = result.getB().substring(0,4);
            yfryResultMap.put(result.getA()+"-"+year,result);
        }
        //研发人员  结束

        //专利获得 开始
        String zlhdResultFileName = "D:\\study\\tmp\\0321\\1\\5上市公司专利获得情况(1).xlsx";
        DemoDataListener<Result0321_3> zlhdResultListener = new DemoDataListener<>();
        EasyExcel.read(zlhdResultFileName, Result0321_3.class,zlhdResultListener).sheet().doRead();
        List<Result0321_3> zlhdResultList = zlhdResultListener.getDataList();

        Map<String,String> zlhdResultMap = new HashMap<>();
        for (Result0321_3 result : zlhdResultList) {
            zlhdResultMap.put(result.getA()+"-"+result.getB(),result.getC());
        }
        //专利获得  结束

        //专利申请 开始
        String zlsqResultFileName = "D:\\study\\tmp\\0321\\1\\6上市公司专利申请情况(1).xlsx";
        DemoDataListener<Result0321_3> zlsqResultListener = new DemoDataListener<>();
        EasyExcel.read(zlsqResultFileName, Result0321_3.class,zlsqResultListener).sheet().doRead();
        List<Result0321_3> zlsqResultList = zlsqResultListener.getDataList();

        Map<String,String> zlsqResultMap = new HashMap<>();
        for (Result0321_3 result : zlsqResultList) {
            zlsqResultMap.put(result.getA()+"-"+result.getB(),result.getC());
        }
        //专利申请  结束

        String dataFileName = "D:\\study\\tmp\\0321\\1\\调整一次0321.xlsx";
        DemoDataListener<FinanceResult0320> dataListener = new DemoDataListener<>();
        EasyExcel.read(dataFileName, FinanceResult0320.class,dataListener).sheet().doRead();
        List<FinanceResult0320> financeList = dataListener.getDataList();
        for (FinanceResult0320 finance : financeList) {
            finance.setT(resultMap.get(finance.getA()+"-"+finance.getB()));
            finance.setU(hzResultMap.get(finance.getK()));
            finance.setV(yfResultMap.get(finance.getA()+"-"+finance.getB()));
            finance.setW(nbResultMap.get(finance.getA()+"-"+finance.getB()));
            if (yfryResultMap.get(finance.getA()+"-"+finance.getB()) != null) {
                finance.setX(yfryResultMap.get(finance.getA()+"-"+finance.getB()).getC());
                finance.setY(yfryResultMap.get(finance.getA()+"-"+finance.getB()).getD());
            }


            finance.setZ(zlhdResultMap.get(finance.getA()+"-"+finance.getB()));
            finance.setAa(zlsqResultMap.get(finance.getA()+"-"+finance.getB()));
        }

        EasyExcel.write("D:\\study\\tmp\\0321\\1\\0321—2结果.xlsx", FinanceResult0320.class)
                .sheet("a").doWrite(financeList);

    }
}
